package com.corpgovernment.travelstandard.impl;

import com.corpgovernment.api.travelstandard.service.IMbTravelstandHotelQuarterService;
import com.corpgovernment.api.travelstandard.vo.MbTravelstandHotelQuarterVo;
import com.corpgovernment.common.base.AbstractBaseService;
import com.corpgovernment.common.base.Page;
import com.corpgovernment.common.utils.ListUtils;
import com.corpgovernment.common.utils.ObjectUtils;
import com.corpgovernment.common.utils.PageUtils;
import com.corpgovernment.travelstandard.convert.HotelStandardConvert;
import com.corpgovernment.travelstandard.entity.db.MbTravelstandHotelQuarter;
import com.corpgovernment.travelstandard.mapper.MbTravelstandHotelQuarterMapper;
import com.ctrip.corp.obt.shard.context.PageContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MbTravelstandHotelQuarterService extends AbstractBaseService implements IMbTravelstandHotelQuarterService {

    @Autowired
    private MbTravelstandHotelQuarterMapper mbTravelstandHotelQuarterMapper;

    @Override
    public void insert(MbTravelstandHotelQuarterVo model) {
        mbTravelstandHotelQuarterMapper.insertSelective(ObjectUtils.copyProperties(model, MbTravelstandHotelQuarter.class));
    }

    @Override
    public int delete(Long id) {
        return mbTravelstandHotelQuarterMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(MbTravelstandHotelQuarterVo model) {
        return mbTravelstandHotelQuarterMapper.updateByPrimaryKeySelective(ObjectUtils.copyProperties(model, MbTravelstandHotelQuarter.class));
    }

    @Override
    public MbTravelstandHotelQuarterVo get(Long id) {
        return HotelStandardConvert.convertToTravelStandardHotel(mbTravelstandHotelQuarterMapper.selectByPrimaryKey(id));
    }

    @Override
    public List<MbTravelstandHotelQuarterVo> list(MbTravelstandHotelQuarterVo model) {
        return HotelStandardConvert.convertToTravelStandardHotelList(mbTravelstandHotelQuarterMapper.list(ObjectUtils.copyProperties(model, MbTravelstandHotelQuarter.class)));
    }

    @Override
    public int deleteByTsId(Long tsId) {
        return mbTravelstandHotelQuarterMapper.deleteByTsId(tsId);
    }

    @Override
    public int deleteByAreaId(Long areaId) {
        return mbTravelstandHotelQuarterMapper.deleteByAreaId(areaId);
    }

    @Override
    public Page page(MbTravelstandHotelQuarterVo model) {
        MbTravelstandHotelQuarter param = ObjectUtils.copyProperties(model, MbTravelstandHotelQuarter.class);
        PageContext.startPage(model.getPageNum(), model.getPageSize());
        List<MbTravelstandHotelQuarter> list = mbTravelstandHotelQuarterMapper.list(param);
        return PageUtils.optPageBy(HotelStandardConvert.convertToTravelStandardHotelList(list), MbTravelstandHotelQuarterVo.class);
    }
}
